<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Utils;

use Hyperf\Amqp\Producer;

class Amqp
{
    /**
     * 向交换机中投递消息.
     */
    public static function pushMessage(string $producerName, string $msg, string $routeingKey = ''): void
    {
        $class = 'App\Amqp\Producer\\' . $producerName;
        $message = new $class($msg);
        if (! empty($routeingKey)) {
            $message->setRoutingKey($routeingKey);
        }
        $producer = Container()->get(Producer::class);
        $producer->produce($message);
    }
}
